package com.cjm.one.payment.app;


import com.alipay.api.AlipayApiException;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.payment.entity.AliPay;
import com.cjm.one.payment.service.PaymentInfoService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/app/pay/alipay")
public class AliPayController {
    @Autowired
    private PaymentInfoService paymentInfoService;

    /**
     * @description: 支付宝支付接口
     * @author: cjm
     * @date: 2025/3/31 22:52
     * @param: [orderNo, httpResponse]
     * @return: void
     **/
    @GetMapping("/pay")
    public Result<String>  pay(@RequestParam("orderNo") String orderNo, HttpServletResponse httpResponse) throws IOException {

        return  Result.ok(paymentInfoService.pay(orderNo, httpResponse));

    }

    /**
     * @description: 支付宝支付异步通知接口
     * @author: cjm
     * @date: 2025/3/31 22:53
     * @param: [request]
     * @return: java.lang.String
     **/
    @PostMapping("/notify")  // 注意这里必须是POST接口
    public Result<String> payNotify(@RequestBody Map<String, String> params) throws Exception {
        String notify = paymentInfoService.notify(params);
        return Result.ok(notify);
    }



}
